package com.tencent.stat.event;

import android.content.Context;
import com.tencent.stat.StatConfig;
import com.tencent.stat.StatSpecifyReportedInfo;
import com.tencent.stat.aw;
import com.tencent.stat.common.DeviceInfo;
import com.tencent.stat.common.StatCommonHelper;
import org.json.JSONObject;

public abstract class e
{
  protected static String j = null;
  private StatSpecifyReportedInfo a = null;
  protected String b = null;
  protected long c;
  protected int d;
  protected DeviceInfo e = null;
  protected int f;
  protected String g = null;
  protected String h = null;
  protected String i = null;
  protected boolean k = false;
  protected Context l;

  e(Context paramContext, int paramInt, StatSpecifyReportedInfo paramStatSpecifyReportedInfo)
  {
    this.l = paramContext;
    this.c = (System.currentTimeMillis() / 1000L);
    this.d = paramInt;
    this.h = StatConfig.getInstallChannel(paramContext);
    this.i = StatCommonHelper.getCurAppVersion(paramContext);
    this.b = StatConfig.getAppKey(paramContext);
    if (paramStatSpecifyReportedInfo != null)
    {
      this.a = paramStatSpecifyReportedInfo;
      if (StatCommonHelper.isStringValid(paramStatSpecifyReportedInfo.getAppKey()))
        this.b = paramStatSpecifyReportedInfo.getAppKey();
      if (StatCommonHelper.isStringValid(paramStatSpecifyReportedInfo.getInstallChannel()))
        this.h = paramStatSpecifyReportedInfo.getInstallChannel();
      if (StatCommonHelper.isStringValid(paramStatSpecifyReportedInfo.getVersion()))
        this.i = paramStatSpecifyReportedInfo.getVersion();
      this.k = paramStatSpecifyReportedInfo.isImportant();
    }
    this.g = StatConfig.getCustomUserId(paramContext);
    this.e = aw.a(paramContext).b(paramContext);
    if (a() != EventType.NETWORK_DETECTOR);
    for (this.f = StatCommonHelper.getNextEventIndexNo(paramContext).intValue(); ; this.f = (-EventType.NETWORK_DETECTOR.a()))
    {
      if (!(com.tencent.mid.util.Util.isMidValid(j)))
      {
        paramContext = StatConfig.getLocalMidOnly(paramContext);
        j = paramContext;
        if (!(StatCommonHelper.isStringValid(paramContext)))
          j = "0";
      }
      return;
    }
  }

  public abstract EventType a();

  public abstract boolean a(JSONObject paramJSONObject);

  public boolean b(JSONObject paramJSONObject)
  {
    try
    {
      com.tencent.stat.common.Util.jsonPut(paramJSONObject, "ky", this.b);
      paramJSONObject.put("et", a().a());
      if (this.e != null)
      {
        paramJSONObject.put("ui", this.e.getImei());
        com.tencent.stat.common.Util.jsonPut(paramJSONObject, "mc", this.e.getMac());
        int i1 = this.e.getUserType();
        paramJSONObject.put("ut", i1);
        if ((i1 == 0) && (StatCommonHelper.isTheFirstTimeActivate(this.l) == 1))
          paramJSONObject.put("ia", 1);
      }
      com.tencent.stat.common.Util.jsonPut(paramJSONObject, "cui", this.g);
      if (a() != EventType.SESSION_ENV)
      {
        com.tencent.stat.common.Util.jsonPut(paramJSONObject, "av", this.i);
        com.tencent.stat.common.Util.jsonPut(paramJSONObject, "ch", this.h);
      }
      if (this.k)
        paramJSONObject.put("impt", 1);
      com.tencent.stat.common.Util.jsonPut(paramJSONObject, "mid", j);
      paramJSONObject.put("idx", this.f);
      paramJSONObject.put("si", this.d);
      paramJSONObject.put("ts", this.c);
      paramJSONObject.put("dts", StatCommonHelper.getDiffTime(this.l, false));
      paramJSONObject.put("os", 1);
      boolean bool = a(paramJSONObject);
      return bool;
    }
    catch (Throwable paramJSONObject)
    {
    }
    return false;
  }

  public long c()
  {
    return this.c;
  }

  public StatSpecifyReportedInfo d()
  {
    return this.a;
  }

  public Context e()
  {
    return this.l;
  }

  public boolean f()
  {
    return this.k;
  }

  public String g()
  {
    try
    {
      Object localObject = new JSONObject();
      b((JSONObject)localObject);
      localObject = ((JSONObject)localObject).toString();
      return localObject;
    }
    catch (Throwable localThrowable)
    {
    }
    return ((String)"");
  }
}